//
//  simProjectViewController.m
//  simens
//
//  Created by amy zhang on 12-7-20.
//  Copyright (c) 2012年 yst. All rights reserved.
//

#import "simProjectViewController.h"
#import "simShopDetailController.h"

@interface simProjectViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic,strong) UITableView *projectTableView;
@property (nonatomic,strong) deviceItem *lastVist;
@property (nonatomic,strong) NSMutableArray *lastVisitArray;
@property (nonatomic,strong) NSString *datelineId;

@end

@implementation simProjectViewController
@synthesize projectTableView=_projectTableView;
@synthesize lastVist=_lastVist;
@synthesize lastVisitArray=_lastVisitArray;
@synthesize datelineId=_datelineId;


- (void)viewDidLoad
{
    [super viewDidLoad];
	self.title=@"上次拜访信息";
    
    self.projectTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 
                                                                       self.view.bounds.size.height) 
                                                      style:UITableViewStyleGrouped];  
    
    [self.projectTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    [self.projectTableView setDelegate:self];
    [self.projectTableView setDataSource:self];
    [self.view addSubview: self.projectTableView];
    
    NSString *url=[NSString stringWithFormat:@"getSiemensCustProStatus?datelineId=%@&mobilePhone=%@&pwd=%@",self.datelineId,[[NSUserDefaults standardUserDefaults]objectForKey:@"LoginMobile"],[[NSUserDefaults standardUserDefaults]objectForKey:@"LoginPassword"]];
    
    simShopDetailController* detailcontroller=[[simShopDetailController alloc] init];  
    NSArray * dictArray=[detailcontroller requestFordata:url objecName:@"siemensCustomer"];
    if(dictArray!=nil){
        for (int i=0;i<dictArray.count; i++) {
            
        }
        
    }
    
    self.lastVist=[[deviceItem alloc] init];
    self.lastVist.name=@"CT";
    self.lastVist.status=@"紧急";
    self.lastVist.date=@"2012-07-18";
    
    
}

-(void)setitems:(NSString*) datelineId{
    self.datelineId=datelineId;
}
 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString* CellIdentifier = [NSString stringWithFormat:@"%d%d",indexPath.section, indexPath.row];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    } 
    
    for (UIView *v in [cell subviews]) {
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    
    UILabel* devicenameLabel =[[UILabel alloc] initWithFrame:CGRectMake(20, 5, 300, 25)];
    [devicenameLabel setBackgroundColor:[UIColor clearColor]];        
    [devicenameLabel setText: [NSString stringWithFormat:@"项目：%@",self.lastVist.name]]; 
    devicenameLabel.font=[UIFont systemFontOfSize:16];
    [cell addSubview:devicenameLabel];
    
    UILabel* statusLabel =[[UILabel alloc] initWithFrame:CGRectMake(20, 30, 300, 25)];
    [statusLabel setBackgroundColor:[UIColor clearColor]];        
    [statusLabel setText:[NSString stringWithFormat:@"项目状态：%@",self.lastVist.status]]; 
    statusLabel.font=[UIFont systemFontOfSize:16];
    [cell addSubview:statusLabel];
    
    UILabel* dateLabel =[[UILabel alloc] initWithFrame:CGRectMake(20, 55, 300, 25)];
    [dateLabel setBackgroundColor:[UIColor clearColor]];        
    [dateLabel setText:[NSString stringWithFormat:@"拜访时间：%@",self.lastVist.date]]; 
    dateLabel.font=[UIFont systemFontOfSize:16];
    [cell addSubview:dateLabel];
   
    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80; 
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30; 
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
    
}// Default is 1 if not implemented

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    
    return @"最近拜访项目";
}// fixed font style. use custom view (UILabel) if you want something different



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
